﻿using Itech_Run.Blog.Application.Contracts.Dto;
using Itech_Run.Blog.Application.Contracts.Service;
using Itech_Run.HttpApi.Shared.Result;
using Itech_Run.Helper.Attribute;
using Itech_Run.HttpApi.Shared;
using Microsoft.AspNetCore.Mvc;

namespace Itech_Run.Blog.HttpApi.Controllers
{
    public class BlogInfoController : BaseApiController
    {
        private readonly IBlogInfoService _blogInfoService;
        public BlogInfoController(IBlogInfoService blogInfoService)
        {
            _blogInfoService = blogInfoService;
        }

        [HttpGet]
        public async Task<CustomResult> GetAsync(string id)
        {
            return new CustomResult(await _blogInfoService.GetAsync(id));
        }

        [HttpPost]
        public async Task<CustomResult> GetListAsync(BlogInfoListDto listDto)
        {
            return new CustomResult(await _blogInfoService.GetListAsync(listDto));
        }

        [ButtonAuth(ButtonAuthConst.add)]
        [HttpPost]
        public async Task<CustomResult> InsertAsync(BlogInfoCreateDto dto)
        {
            string operateUser = GetOperateId();
            return new CustomResult(await _blogInfoService.InsertAsync(dto, operateUser));
        }

        [ButtonAuth(ButtonAuthConst.edit)]
        [HttpPost]
        public async Task<CustomResult> UpdateAsync(BlogInfoUpdateDto dto)
        {
            string operateUser = GetOperateId();
            return new CustomResult(await _blogInfoService.UpdateAsync(dto, operateUser));
        }

        [ButtonAuth(ButtonAuthConst.delete)]
        [HttpPost]
        public async Task<CustomResult> DeleteAsync(string id)
        {
            string operateUser = GetOperateId();
            await _blogInfoService.DeleteAsync(id, operateUser);
            return GetSuccesResult();
        }
    }
}
